package cn.itcast.travel.web.servlet.admin;

import cn.itcast.travel.domain.blogger;
import cn.itcast.travel.service.AdminService;
import cn.itcast.travel.service.impl.AdminServiceImpl;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet(name = "handleuser", value = "/handleuser")
public class handleuser extends HttpServlet {
    AdminService service=new AdminServiceImpl();
    //删除用户
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id=request.getParameter("id");
        service.deleteuser(id);
        ObjectMapper ob=new ObjectMapper();
        ob.writeValue(response.getWriter(),1);
    }

    //修改用户信息
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map mp=request.getParameterMap();
        blogger br=new blogger();
        try {
            BeanUtils.populate(br,mp);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        service.xiugai(br);
        ObjectMapper ob=new ObjectMapper();
        ob.writeValue(response.getWriter(),1);
    }
}
